package com.css.zfzx.sjcj.modules.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.utils.PlatformObjectUtils;
import com.css.bpm.platform.utils.PlatformPageUtils;
import com.css.zfzx.sjcj.common.Constant;
import com.css.zfzx.sjcj.common.StatisticsEnum;
import com.css.zfzx.sjcj.common.division.repository.MyDivisionRepository;
import com.css.zfzx.sjcj.common.utils.CheckObjFields;
import com.css.zfzx.sjcj.common.utils.ServerUtil;
import com.css.zfzx.sjcj.common.vo.DivisionVo;
import com.css.zfzx.sjcj.modules.pojo.PcStatisticsFillEntity;
import com.css.zfzx.sjcj.modules.pojo.PcStatisticsFillVO;
import com.css.zfzx.sjcj.modules.pojo.QueryVo;
import com.css.zfzx.sjcj.modules.repository.MyPcStatisticsFillRepository;
import com.css.zfzx.sjcj.modules.repository.PcStatisticsFillNativeRepository;
import com.css.zfzx.sjcj.modules.repository.PcStatisticsFillRepository;
import com.css.zfzx.sjcj.modules.service.PcStatisticsFillService;
import com.css.zfzx.sjcj.modules.statistics.fxCasualtyEvaluationMap.repository.entity.FxCasualtyEvaluationMapEntity;
import com.css.zfzx.sjcj.modules.statistics.fxCasualtyEvaluationMap.service.FxCasualtyEvaluationMapService;
import com.css.zfzx.sjcj.modules.statistics.fxCasualtyLevelMap.repository.entity.FxCasualtyLevelMapEntity;
import com.css.zfzx.sjcj.modules.statistics.fxCasualtyLevelMap.service.FxCasualtyLevelMapService;
import com.css.zfzx.sjcj.modules.statistics.fxEconomicLossEvaluationMap.repository.entity.FxEconomicLossEvaluationMapEntity;
import com.css.zfzx.sjcj.modules.statistics.fxEconomicLossEvaluationMap.service.FxEconomicLossEvaluationMapService;
import com.css.zfzx.sjcj.modules.statistics.fxEconomicLossLevelMap.repository.entity.FxEconomicLossLevelMapEntity;
import com.css.zfzx.sjcj.modules.statistics.fxEconomicLossLevelMap.service.FxEconomicLossLevelMapService;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc100.repository.entity.FxqhHdc100Entity;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc100.service.FxqhHddc100Service;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc200.repository.entity.FxqhHdc200Entity;
import com.css.zfzx.sjcj.modules.statistics.fxqhHddc200.service.FxqhHddc200Service;
import com.css.zfzx.sjcj.modules.statistics.fxqhPriority.repository.entity.FxqhPriorityEntity;
import com.css.zfzx.sjcj.modules.statistics.fxqhPriority.service.FxqhPrioritysService;
import com.css.zfzx.sjcj.modules.statistics.hdcActiveFault.repository.entity.HddcActivefaultEntity;
import com.css.zfzx.sjcj.modules.statistics.hdcActiveFault.service.HdcActiveFaultService;
import com.css.zfzx.sjcj.modules.statistics.hdcDResultmaptable.repository.entity.HddcDResultmaptableEntity;
import com.css.zfzx.sjcj.modules.statistics.hdcDResultmaptable.service.HdcDResultmaptableService;
import com.css.zfzx.sjcj.modules.statistics.hdcActivefaultPositionerror.repository.entity.HddcActivefaultPositionerrorEntity;
import com.css.zfzx.sjcj.modules.statistics.hdcActivefaultPositionerror.service.HdcActivefaultPositionerrorService;
import com.css.zfzx.sjcj.modules.statistics.qhProbabilityEarthquakeDanger.repository.entity.QhProbabilityEarthquakeDangerEntity;
import com.css.zfzx.sjcj.modules.statistics.qhProbabilityEarthquakeDanger.service.QhProbabilityEarthquakeDangerService;
import com.css.zfzx.sjcj.modules.statistics.qhRiskLevelMapPoint.repository.entity.QhRiskLevelMapPointEntity;
import com.css.zfzx.sjcj.modules.statistics.qhRiskLevelMapPoint.service.QhRiskLevelMapPointService;
import com.css.zfzx.sjcj.modules.statistics.qhRiskLevelMapPolygon.repository.entity.QhRiskLevelMapPolygonEntity;
import com.css.zfzx.sjcj.modules.statistics.qhRiskLevelMapPolygon.service.QhRiskLevelMapPolygonService;
import com.css.zfzx.sjcj.modules.statistics.yhDisaster.repository.entity.YhDisasterEntity;
import com.css.zfzx.sjcj.modules.statistics.yhDisaster.service.YhDisasterService;
import com.css.zfzx.sjcj.modules.sys.attachmet.repository.AttachmentsRepository;
import com.css.zfzx.sjcj.modules.sys.usersInfo.repository.UsersInfoRepository;
import com.css.zfzx.sjcj.modules.sys.usersInfo.UsersVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @Description: pc-statistics
 * @Author: lhl
 * @CreateDate: 2021/8/2 11:34
 */
@Service
public class PcStatisticsFillServiceImpl implements PcStatisticsFillService {
    @Autowired
    PcStatisticsFillRepository pcStatisticsFillRepository;
    @Autowired
    PcStatisticsFillNativeRepository pcStatisticsFillNativeRepository;
    @Autowired
    MyPcStatisticsFillRepository myPcStatisticsFillRepository;

    @Autowired
    HdcActiveFaultService hdcActiveFaultService;
    @Autowired
    HdcActivefaultPositionerrorService hdcActivefaultPositionerrorService;
    @Autowired
    HdcDResultmaptableService hdcDResultmaptableService;
    @Autowired
    QhProbabilityEarthquakeDangerService qhProbabilityEarthquakeDangerService;
    @Autowired
    QhRiskLevelMapPointService qhRiskLevelMapPointService;
    @Autowired
    QhRiskLevelMapPolygonService qhRiskLevelMapPolygonService;
    @Autowired
    YhDisasterService yhDisasterService;
    @Autowired
    FxqhPrioritysService fxqhPrioritysService;
    @Autowired
    FxqhHddc100Service fxqhHddc100Service;
    @Autowired
    FxqhHddc200Service fxqhHddc200Service;
    @Autowired
    FxEconomicLossLevelMapService fxEconomicLossLevelMapService;
    @Autowired
    FxCasualtyLevelMapService fxCasualtyLevelMapService;
    @Autowired
    FxEconomicLossEvaluationMapService fxEconomicLossEvaluationMapService;
    @Autowired
    FxCasualtyEvaluationMapService fxCasualtyEvaluationMapService;

    @Autowired
    MyDivisionRepository myDivisionRepository;
    @Autowired
    UsersInfoRepository usersInfoRepository;
    @Autowired
    AttachmentsRepository attachmentsRepository;

    public static List<DivisionVo> areaList = new ArrayList<>();
    public static List<UsersVo> usersVoList = new ArrayList<>();
    //public static List<AttachmetVo> attachmetVoList = new ArrayList<>();

    public List<DivisionVo> voList = new ArrayList<>();

    @PostConstruct
    //@Before
    public void init() {
        areaList = myDivisionRepository.findIsPioneer();
        usersVoList = usersInfoRepository.getAll();
        //attachmetVoList = attachmentsRepository.getAll();
    }

    @Override
    public JSONObject find(QueryVo queryVo, String userId, int curPage, int pageSize, String sort, String order) {
        if (!PlatformObjectUtils.isEmpty(sort) && sort.length() > 0) {
            sort = CheckObjFields.propertyChange(sort);
        }

        List<PcStatisticsFillEntity> saveList = new ArrayList<>();
        List<PcStatisticsFillEntity> updateList = new ArrayList<>();
        StatisticsEnum anEnum = StatisticsEnum.getInstanceByName(queryVo.getTaskName());
        String taskName = anEnum.getTaskName();
        queryVo.setTaskName(taskName);
        List<DivisionVo> divisionVos = myPcStatisticsFillRepository.findByTaskName(taskName);
        if ("1".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = hdcActiveFaultService.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = hdcActiveFaultService.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("2".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = hdcActivefaultPositionerrorService.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = hdcActivefaultPositionerrorService.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("3".equals(anEnum.getTaskId()) || "4".equals(anEnum.getTaskId()) || "5".equals(anEnum.getTaskId()) || "6".equals(anEnum.getTaskId()) || "7".equals(anEnum.getTaskId()) || "8".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            int identify = 0;
            if ("4".equals(anEnum.getTaskId()) || "5".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("7".equals(anEnum.getTaskId()) || "8".equals(anEnum.getTaskId())) {
                identify = 4;
            }
            List<HddcDResultmaptableEntity> entities1 = new ArrayList<>();
            List<HddcDResultmaptableEntity> entities3 = new ArrayList<>();
            String date = null;
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            if (!("3".equals(anEnum.getTaskId()) || "6".equals(anEnum.getTaskId()))) {
                if (createTime == null) {
                    date = "2021-08-02 23:59:59";
                    createTime = LocalDateTime.parse(date, formatter);
                    entities1 = hdcDResultmaptableService.findCreateTime(createTime, identify);
                }
                if (updateTime == null) {
                    date = "2021-08-02 23:59:59";
                    updateTime = LocalDateTime.parse(date, formatter);
                    entities3 = hdcDResultmaptableService.findUpdateTime(updateTime, identify);
                }
            }
            if ("3".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("4".equals(anEnum.getTaskId())) {
                identify = 2;
            } else if ("5".equals(anEnum.getTaskId())) {
                identify = 3;
            } else if ("6".equals(anEnum.getTaskId())) {
                identify = 4;
            } else if ("7".equals(anEnum.getTaskId())) {
                identify = 5;
            } else if ("8".equals(anEnum.getTaskId())) {
                identify = 6;
            }
            if (StringUtils.isNotEmpty(date)) {
                date = "2021-08-03 00:00:00";
                createTime = LocalDateTime.parse(date, formatter);
                updateTime = LocalDateTime.parse(date, formatter);
            }
            List<HddcDResultmaptableEntity> entities2 = hdcDResultmaptableService.findCreateTime(createTime, identify);
            List<HddcDResultmaptableEntity> entities4 = hdcDResultmaptableService.findUpdateTime(updateTime, identify);
            for (HddcDResultmaptableEntity entity : entities2) {
                entities1.add(entity);
            }
            for (HddcDResultmaptableEntity entity : entities4) {
                entities3.add(entity);
            }
            for (HddcDResultmaptableEntity entity : entities1) {
                PcStatisticsFillEntity pcEntity = getCreateEntity(anEnum, entity, null, Constant.createFields, userId,
                        true);
                pcEntity.setAttachmetName(entity.getFilename());
                pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + entity.getFilename());
                saveList.add(pcEntity);
            }

            for (HddcDResultmaptableEntity entity : entities3) {
                PcStatisticsFillEntity pcEntity = pcStatisticsFillRepository.findByDataId(entity.getProvince(),
                        entity.getCity(), entity.getArea(), taskName);
                String attachmentName = entity.getFilename();
                if (pcEntity == null) {
                    pcEntity = getCreateEntity(anEnum, entity, null, Constant.updateFields1, userId, false);
                    pcEntity.setAttachmetName(attachmentName);
                    pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    saveList.add(pcEntity);
                } else {
                    pcEntity = getUpdateEntity(anEnum, pcEntity, entity, Constant.updateFields2, userId, null);
                    if (StringUtils.isNotEmpty(attachmentName) && !attachmentName.equals(pcEntity.getAttachmetName())) {
                        pcEntity.setAttachmetName(attachmentName);
                        pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    }
                    updateList.add(pcEntity);
                }
            }
        } else if ("9".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = qhProbabilityEarthquakeDangerService.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = qhProbabilityEarthquakeDangerService.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("10".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = qhRiskLevelMapPointService.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = qhRiskLevelMapPointService.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("11".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = qhRiskLevelMapPolygonService.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = qhRiskLevelMapPolygonService.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("12".equals(anEnum.getTaskId()) || "13".equals(anEnum.getTaskId()) || "14".equals(anEnum.getTaskId())) {
            int identify = 0;
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            if ("12".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("13".equals(anEnum.getTaskId())) {
                identify = 2;
            } else if ("14".equals(anEnum.getTaskId())) {
                identify = 3;
            }
            List<YhDisasterEntity> entities1 = yhDisasterService.findCreateTime(createTime, identify);
            for (YhDisasterEntity entity : entities1) {
                PcStatisticsFillEntity pcEntity = getCreateEntity(anEnum, entity, null, Constant.createFields, userId,
                        true);
                pcEntity.setAttachmetName(entity.getImageUrl());
                pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + entity.getImageUrl());

                saveList.add(pcEntity);
            }

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<YhDisasterEntity> entities2 = yhDisasterService.findUpdateTime(updateTime, identify);
            for (YhDisasterEntity entity : entities2) {
                PcStatisticsFillEntity pcEntity = pcStatisticsFillRepository.findByDataId(entity.getProvince(),
                        entity.getCity(), entity.getArea(), taskName);
                String attachmentName = entity.getImageUrl();
                if (pcEntity == null) {
                    pcEntity = getCreateEntity(anEnum, entity, null, Constant.updateFields1, userId, false);
                    pcEntity.setAttachmetName(attachmentName);
                    pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    saveList.add(pcEntity);
                } else {
                    pcEntity = getUpdateEntity(anEnum, pcEntity, entity, Constant.updateFields2, userId, null);
                    if (StringUtils.isNotEmpty(attachmentName) && !attachmentName.equals(pcEntity.getAttachmetName())) {
                        pcEntity.setAttachmetName(attachmentName);
                        pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    }
                    updateList.add(pcEntity);
                }
            }
        } else if ("15".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = fxqhPrioritysService.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = fxqhPrioritysService.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("16".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = fxqhHddc100Service.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = fxqhHddc100Service.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("17".equals(anEnum.getTaskId())) {
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            List<PcStatisticsFillVO> entities1 = fxqhHddc200Service.findCreateTime(createTime);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = fxqhHddc200Service.findUpdateTime(updateTime);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("18".equals(anEnum.getTaskId()) || "19".equals(anEnum.getTaskId()) || "20".equals(anEnum.getTaskId()) || "21".equals(anEnum.getTaskId())) {
            int identify = 0;
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            if ("18".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("19".equals(anEnum.getTaskId())) {
                identify = 2;
            } else if ("20".equals(anEnum.getTaskId())) {
                identify = 3;
            } else if ("21".equals(anEnum.getTaskId())) {
                identify = 4;
            }
            List<PcStatisticsFillVO> entities1 = fxEconomicLossLevelMapService.findCreateTime(createTime, identify);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = fxEconomicLossLevelMapService.findUpdateTime(updateTime, identify);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("22".equals(anEnum.getTaskId()) || "23".equals(anEnum.getTaskId()) || "24".equals(anEnum.getTaskId()) || "25".equals(anEnum.getTaskId())) {
            int identify = 0;
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            if ("22".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("23".equals(anEnum.getTaskId())) {
                identify = 2;
            } else if ("24".equals(anEnum.getTaskId())) {
                identify = 3;
            } else if ("25".equals(anEnum.getTaskId())) {
                identify = 4;
            }
            List<PcStatisticsFillVO> entities1 = fxCasualtyLevelMapService.findCreateTime(createTime, identify);

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<PcStatisticsFillVO> entities2 = fxCasualtyLevelMapService.findUpdateTime(updateTime, identify);
            Map<String, List<PcStatisticsFillEntity>> list = getList(splitList(entities1, divisionVos), splitList(entities2, divisionVos), anEnum, userId);
            saveList = list.get("save");
            updateList = list.get("update");
        } else if ("26".equals(anEnum.getTaskId()) || "27".equals(anEnum.getTaskId()) || "28".equals(anEnum.getTaskId()) || "29".equals(anEnum.getTaskId())) {
            int identify = 0;
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            if ("26".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("27".equals(anEnum.getTaskId())) {
                identify = 2;
            } else if ("28".equals(anEnum.getTaskId())) {
                identify = 3;
            } else if ("29".equals(anEnum.getTaskId())) {
                identify = 4;
            }
            List<FxEconomicLossEvaluationMapEntity> entities1 = fxEconomicLossEvaluationMapService.findCreateTime(createTime, identify);
            List<FxEconomicLossEvaluationMapEntity> subEntities1 = new ArrayList<>();
            List<FxEconomicLossEvaluationMapEntity> subEntities2 = new ArrayList<>();
            if (entities1.size() > 0) {
                for (FxEconomicLossEvaluationMapEntity entity : entities1) {
                    if (getsubEntities(entity, Constant.fields, taskName)) {
                        DivisionVo divisionVo = new DivisionVo();
                        divisionVo.setProvinceName(entity.getProvince());
                        divisionVo.setCityName(entity.getCity());
                        divisionVo.setAreaName(entity.getArea());
                        if (!divisionVos.contains(divisionVo)) {
                            subEntities1.add(entity);
                        } else {
                            subEntities2.add(entity);
                        }
                    }
                }
            }
            for (FxEconomicLossEvaluationMapEntity entity : subEntities1) {
                PcStatisticsFillEntity pcEntity = getCreateEntity(anEnum, entity, null, Constant.createFields, userId,
                        true);
                pcEntity.setAttachmetName(entity.getAffiliatedFileName());
                pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + entity.getAffiliatedFileName());

                saveList.add(pcEntity);
            }

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<FxEconomicLossEvaluationMapEntity> entities2 = fxEconomicLossEvaluationMapService.findUpdateTime(updateTime, identify);
            if (entities2.size() > 0) {
                for (FxEconomicLossEvaluationMapEntity entity : entities2) {
                    if (getsubEntities(entity, Constant.fields, taskName)) {
                        subEntities2.add(entity);
                    }
                }
            }
            for (FxEconomicLossEvaluationMapEntity entity : subEntities2) {
                if (getsubEntities(entity, Constant.fields, taskName)) {
                    DivisionVo divisionVo = new DivisionVo();
                    divisionVo.setProvinceName(entity.getProvince());
                    divisionVo.setCityName(entity.getCity());
                    divisionVo.setAreaName(entity.getArea());
                    if (!divisionVos.contains(divisionVo)) {
                        subEntities2.add(entity);
                    }
                }
            }
            for (FxEconomicLossEvaluationMapEntity entity : subEntities2) {
                PcStatisticsFillEntity pcEntity = pcStatisticsFillRepository.findByDataId(entity.getProvince(),
                        entity.getCity(), entity.getArea(), taskName);
                String attachmentName = entity.getAffiliatedFileName();
                if (pcEntity == null) {
                    pcEntity = getCreateEntity(anEnum, entity, null, Constant.updateFields1, userId, false);
                    pcEntity.setAttachmetName(attachmentName);
                    pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    saveList.add(pcEntity);
                } else {
                    pcEntity = getUpdateEntity(anEnum, pcEntity, entity, Constant.updateFields2, userId, null);
                    if (StringUtils.isNotEmpty(attachmentName) && !attachmentName.equals(pcEntity.getAttachmetName())) {
                        pcEntity.setAttachmetName(attachmentName);
                        pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    }
                    updateList.add(pcEntity);
                }
            }
        } else if ("30".equals(anEnum.getTaskId()) || "31".equals(anEnum.getTaskId()) || "32".equals(anEnum.getTaskId()) || "33".equals(anEnum.getTaskId())) {
            int identify = 0;
            LocalDateTime createTime = pcStatisticsFillRepository.getCreateTime(taskName);
            if ("30".equals(anEnum.getTaskId())) {
                identify = 1;
            } else if ("31".equals(anEnum.getTaskId())) {
                identify = 2;
            } else if ("32".equals(anEnum.getTaskId())) {
                identify = 3;
            } else if ("33".equals(anEnum.getTaskId())) {
                identify = 4;
            }
            List<FxCasualtyEvaluationMapEntity> entities1 = fxCasualtyEvaluationMapService.findCreateTime(createTime, identify);
            List<FxCasualtyEvaluationMapEntity> subEntities1 = new ArrayList<>();
            List<FxCasualtyEvaluationMapEntity> subEntities2 = new ArrayList<>();
            if (entities1.size() > 0) {
                for (FxCasualtyEvaluationMapEntity entity : entities1) {
                    if (getsubEntities(entity, Constant.fields, taskName)) {
                        DivisionVo divisionVo = new DivisionVo();
                        divisionVo.setProvinceName(entity.getProvince());
                        divisionVo.setCityName(entity.getCity());
                        divisionVo.setAreaName(entity.getArea());
                        if (!divisionVos.contains(divisionVo)) {
                            subEntities1.add(entity);
                        } else {
                            subEntities2.add(entity);
                        }
                    }
                }
            }
            for (FxCasualtyEvaluationMapEntity entity : subEntities1) {
                PcStatisticsFillEntity pcEntity = getCreateEntity(anEnum, entity, null, Constant.createFields, userId,
                        true);
                pcEntity.setAttachmetName(entity.getAffiliatedFileName());
                pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + entity.getAffiliatedFileName());

                saveList.add(pcEntity);
            }

            LocalDateTime updateTime = pcStatisticsFillRepository.getUpdateTime(taskName);
            List<FxCasualtyEvaluationMapEntity> entities2 = fxCasualtyEvaluationMapService.findUpdateTime(updateTime, identify);

            if (entities2.size() > 0) {
                for (FxCasualtyEvaluationMapEntity entity : entities2) {
                    if (getsubEntities(entity, Constant.fields, taskName)) {
                        subEntities2.add(entity);
                    }
                }
            }
            for (FxCasualtyEvaluationMapEntity entity : subEntities2) {
                if (getsubEntities(entity, Constant.fields, taskName)) {
                    DivisionVo divisionVo = new DivisionVo();
                    divisionVo.setProvinceName(entity.getProvince());
                    divisionVo.setCityName(entity.getCity());
                    divisionVo.setAreaName(entity.getArea());
                    if (!divisionVos.contains(divisionVo)) {
                        subEntities2.add(entity);
                    }
                }
            }
            for (FxCasualtyEvaluationMapEntity entity : subEntities2) {
                PcStatisticsFillEntity pcEntity = pcStatisticsFillRepository.findByDataId(entity.getProvince(),
                        entity.getCity(), entity.getArea(), taskName);
                String attachmentName = entity.getAffiliatedFileName();
                if (pcEntity == null) {
                    pcEntity = getCreateEntity(anEnum, entity, null, Constant.updateFields1, userId, false);
                    pcEntity.setAttachmetName(attachmentName);
                    pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    saveList.add(pcEntity);
                } else {
                    pcEntity = getUpdateEntity(anEnum, pcEntity, entity, Constant.updateFields2, userId, null);
                    if (StringUtils.isNotEmpty(attachmentName) && !attachmentName.equals(pcEntity.getAttachmetName())) {
                        pcEntity.setAttachmetName(attachmentName);
                        pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
                    }
                    updateList.add(pcEntity);
                }
            }
        }
        clear();
        if (saveList.size() > 0) {
            pcStatisticsFillNativeRepository.batchSave(saveList);
        }
        if (updateList.size() > 0) {
            pcStatisticsFillNativeRepository.batchUpdate(updateList);
        }

        Page<PcStatisticsFillEntity> pcList = pcStatisticsFillNativeRepository.find(queryVo, userId, curPage, pageSize,
                sort, order);
        for (PcStatisticsFillEntity pcEntity : pcList.getContent()) {
            String uploadUser = pcEntity.getUploadUser();
            for (UsersVo usersVo : usersVoList) {
                if (usersVo.getUsersId().equals(uploadUser)) {
                    pcEntity.setUploadUser(usersVo.getUsersName());
                    break;
                }
            }
        }
        JSONObject jsonObject = PlatformPageUtils.formatPageData(pcList);
        return jsonObject;
    }

    public Map<String, List<PcStatisticsFillEntity>> getList(Map<String, List<PcStatisticsFillVO>> listMap1, Map<String,
            List<PcStatisticsFillVO>> listMap2, StatisticsEnum anEnum, String userId) {
        Map<String, List<PcStatisticsFillEntity>> list = new HashMap<>();
        List<PcStatisticsFillEntity> saveList = new ArrayList<>();
        List<PcStatisticsFillEntity> updateList = new ArrayList<>();
        String taskName = anEnum.getTaskName();
        if (listMap1.containsKey("save")) {
            if (listMap2.containsKey("save")) {
                listMap1.get("save").addAll(listMap2.get("save"));
            }
            for (PcStatisticsFillVO entity : listMap1.get("save")) {
                PcStatisticsFillEntity pcEntity = getCreateEntity1(anEnum, entity, userId, true);
                pcEntity.setAttachmetName(entity.getAttachmentName());
                pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + entity.getAttachmentName());
                saveList.add(pcEntity);
            }
        }
        if (listMap1.containsKey("update")) {
            for (PcStatisticsFillVO entity : listMap1.get("update")) {
                PcStatisticsFillEntity pcEntity = pcStatisticsFillRepository.findByDataId(entity.getProvince(),
                        entity.getCity(), entity.getArea(), taskName);
                if(pcEntity.getTotalCount()!=null) {
                    pcEntity.setTotalCount(pcEntity.getTotalCount().add(entity.getTotalCount()));
                }else {
                    pcEntity.setTotalCount(entity.getTotalCount());
                }
                if(pcEntity.getReportCount()!=null) {
                    pcEntity.setReportCount(pcEntity.getReportCount().add(entity.getReportCount()));
                }else {
                    pcEntity.setReportCount(entity.getReportCount());
                }
                if (pcEntity.getTotalCount().equals(pcEntity.getReportCount())) {
                    pcEntity.setIsReportPg("1");
                }else {
                    pcEntity.setIsReportPg("0");
                }
                pcEntity = getUpdateEntity1(anEnum, pcEntity, entity, userId);
                updateList.add(pcEntity);
            }
        }
        if (listMap2.containsKey("update")) {
            for (PcStatisticsFillVO entity : listMap2.get("update")) {
                PcStatisticsFillEntity pcEntity = pcStatisticsFillRepository.findByDataId(entity.getProvince(),
                        entity.getCity(), entity.getArea(), taskName);
                //pcEntity.setTotalCount(pcEntity.getTotalCount());
                //pcEntity.setReportCount(pcEntity.getReportCount());
                if (pcEntity.getTotalCount()==null){
                    pcEntity.setTotalCount(BigInteger.ZERO);
                }
                if (pcEntity.getReportCount()==null){
                    pcEntity.setReportCount(BigInteger.ZERO);
                }
                if (pcEntity.getTotalCount().equals(pcEntity.getReportCount())) {
                    pcEntity.setIsReportPg("1");
                }else {
                    pcEntity.setIsReportPg("0");
                }
                pcEntity = getUpdateEntity1(anEnum, pcEntity, entity, userId);
                updateList.add(pcEntity);
            }
        }
        list.put("save", saveList);
        list.put("update", updateList);
        return list;
    }

    public Map<String, List<PcStatisticsFillVO>> splitList(List<PcStatisticsFillVO> entities, List<DivisionVo> divisionVos) {
        Map<String, List<PcStatisticsFillVO>> listMap = new HashMap<>();
        List<PcStatisticsFillVO> subEntities1 = new ArrayList<>();//要保存的数据
        List<PcStatisticsFillVO> subEntities2 = new ArrayList<>();//要修改的数据
        if (entities.size() > 0) {
            for (PcStatisticsFillVO entity : entities) {
                DivisionVo divisionVo = new DivisionVo();
                divisionVo.setProvinceName(entity.getProvince());
                divisionVo.setCityName(entity.getCity());
                divisionVo.setAreaName(entity.getArea());
                if (!divisionVos.contains(divisionVo)) {
                    subEntities1.add(entity);
                } else {
                    subEntities2.add(entity);
                }
            }
            listMap.put("save", subEntities1);
            listMap.put("update", subEntities2);
        }
        return listMap;
    }

    public PcStatisticsFillEntity getCreateEntity(StatisticsEnum anEnum, Object obj, List<DivisionVo> count, String[] fields, String userId,
                                                  Boolean isNa) {
        PcStatisticsFillEntity pcEntity = new PcStatisticsFillEntity();
        try {
            pcEntity.setId(String.valueOf(UUID.randomUUID()));
            String dataId = (String) ServerUtil.getGetMethod(obj, fields[3]);
            String createUser = (String) ServerUtil.getGetMethod(obj, fields[4]);
            Date createTime = (Date) ServerUtil.getGetMethod(obj, fields[5]);
            pcEntity.setDataId(dataId);
            if (StringUtils.isNotEmpty(createUser)) {
                pcEntity.setUploadUser(createUser);
            } else {
                pcEntity.setUploadUser(userId);
            }
            pcEntity.setTaskCreateTime(createTime);
            pcEntity.setUploadTime(createTime);
            pcEntity.setIsValid("1");
            if (isNa) {
                pcEntity.setUploadTime(createTime);
            } else {
                Date updateTime = (Date) ServerUtil.getGetMethod(obj, fields[6]);
                pcEntity.setUploadTime(updateTime);
                pcEntity.setTaskUpdateTime(updateTime);
            }
            pcEntity.setTaskName(anEnum.getTaskName());
            pcEntity.setTaskTable(anEnum.getTaskTable());
            String province = (String) ServerUtil.getGetMethod(obj, fields[0]);
            String city = (String) ServerUtil.getGetMethod(obj, fields[1]);
            String area = (String) ServerUtil.getGetMethod(obj, fields[2]);
            pcEntity.setProvince(province);
            pcEntity.setCity(city);
            pcEntity.setArea(area);
            for (DivisionVo vo : areaList) {
                String divisionName = vo.getProvinceName();
                if (divisionName.equals(area) || divisionName.equals(city)
                        || divisionName.equals(province)) {
                    pcEntity.setIsPioneer("Y");
                    break;
                } else {
                    pcEntity.setIsPioneer("N");
                }
            }
            if (count.size() > 0) {
                for (DivisionVo vo : count) {
                    if (province.equals(vo.getProvinceName()) && city.equals(vo.getCityName()) && area.equals(vo.getAreaName())) {
                        pcEntity.setIsReportPg("1");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pcEntity;
    }

    public PcStatisticsFillEntity getCreateEntity1(StatisticsEnum anEnum, PcStatisticsFillVO obj, String userId,
                                                   Boolean isNa) {
        PcStatisticsFillEntity pcEntity = new PcStatisticsFillEntity();
        try {
            pcEntity.setId(String.valueOf(UUID.randomUUID()));
            pcEntity.setTaskName(anEnum.getTaskName());
            pcEntity.setTaskTable(anEnum.getTaskTable());
            String province = obj.getProvince();
            String city = obj.getCity();
            String area = obj.getArea();
            pcEntity.setProvince(province);
            pcEntity.setCity(city);
            pcEntity.setArea(area);
            for (DivisionVo vo : areaList) {
                String divisionName = vo.getProvinceName();
                if (divisionName.equals(area) || divisionName.equals(city)
                        || divisionName.equals(province)) {
                    pcEntity.setIsPioneer("Y");
                    break;
                } else {
                    pcEntity.setIsPioneer("N");
                }
            }
            if (obj.getTotalCount()==null){
                pcEntity.setTotalCount(BigInteger.ZERO);
            }else {
                pcEntity.setTotalCount(obj.getTotalCount());
            }
            if (obj.getReportCount()==null){
                pcEntity.setReportCount(BigInteger.ZERO);
            }else {
                pcEntity.setReportCount(obj.getReportCount());
            }
            if (obj.getTotalCount().equals(obj.getReportCount())) {
                pcEntity.setIsReportPg("1");
            }else {
                pcEntity.setIsReportPg("0");
            }
            String createUser = obj.getCreateUser();
            Date createTime = obj.getCreateTime();
            if (StringUtils.isNotEmpty(createUser)) {
                pcEntity.setUploadUser(createUser);
            } else {
                pcEntity.setUploadUser(userId);
            }
            pcEntity.setTaskCreateTime(createTime);
            pcEntity.setUploadTime(createTime);
            pcEntity.setIsValid("1");
            if (obj.getUpdateTime() == null) {
                pcEntity.setUploadTime(createTime);
            } else {
                Date updateTime = obj.getUpdateTime();
                pcEntity.setUploadTime(updateTime);
                pcEntity.setTaskUpdateTime(updateTime);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pcEntity;
    }

    public PcStatisticsFillEntity getUpdateEntity(StatisticsEnum anEnum, PcStatisticsFillEntity pcEntity, Object obj,
                                                  String[] fields, String userId, List<DivisionVo> count) {
        pcEntity.setTaskName(anEnum.getTaskName());
        pcEntity.setTaskTable(anEnum.getTaskTable());
        try {
            String province = (String) ServerUtil.getGetMethod(obj, fields[0]);
            String city = (String) ServerUtil.getGetMethod(obj, fields[1]);
            String area = (String) ServerUtil.getGetMethod(obj, fields[2]);
            String isValid = (String) ServerUtil.getGetMethod(obj, fields[3]);
            String updateUser = (String) ServerUtil.getGetMethod(obj, fields[4]);
            Date updateTime = (Date) ServerUtil.getGetMethod(obj, fields[5]);
            if (count.size() > 0) {
                for (DivisionVo vo : count) {
                    if (province.equals(vo.getProvinceName()) && city.equals(vo.getCityName()) && area.equals(vo.getAreaName())) {
                        pcEntity.setIsReportPg("1");
                    }
                }
            }
            if (StringUtils.isNotEmpty(province) && !province.equals(pcEntity.getProvince())) {
                pcEntity.setProvince(province);
            }
            if (StringUtils.isNotEmpty(city) && !city.equals(pcEntity.getCity())) {
                pcEntity.setCity(city);
            }
            pcEntity.setIsValid(isValid);
            if (StringUtils.isNotEmpty(area) && !area.equals(pcEntity.getArea())) {
                pcEntity.setArea(area);
            }
            for (DivisionVo vo : areaList) {
                String divisionName = vo.getProvinceName();
                if (divisionName.equals(area) || divisionName.equals(city)
                        || divisionName.equals(province)) {
                    pcEntity.setIsPioneer("Y");
                } else {
                    pcEntity.setIsPioneer("N");
                }
            }
            if (StringUtils.isNotEmpty(updateUser)) {
                pcEntity.setUploadUser(updateUser);
            } else {
                pcEntity.setUploadUser(userId);
            }
            pcEntity.setUploadTime(updateTime);
            pcEntity.setTaskUpdateTime(updateTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pcEntity;
    }

    public PcStatisticsFillEntity getUpdateEntity1(StatisticsEnum anEnum, PcStatisticsFillEntity pcEntity, PcStatisticsFillVO obj,
                                                   String userId) {
        pcEntity.setTaskName(anEnum.getTaskName());
        pcEntity.setTaskTable(anEnum.getTaskTable());
        try {
            String province = obj.getProvince();
            String city = obj.getCity();
            String area = obj.getArea();
            String isValid = obj.getIsValid();
            String updateUser = obj.getUpdateUser();
            Date updateTime = obj.getUpdateTime();
            if (StringUtils.isNotEmpty(province) && !province.equals(pcEntity.getProvince())) {
                pcEntity.setProvince(province);
            }
            if (StringUtils.isNotEmpty(city) && !city.equals(pcEntity.getCity())) {
                pcEntity.setCity(city);
            }
            if (StringUtils.isNotEmpty(area) && !area.equals(pcEntity.getArea())) {
                pcEntity.setArea(area);
            }
            for (DivisionVo vo : areaList) {
                String divisionName = vo.getProvinceName();
                if (divisionName.equals(area) || divisionName.equals(city)
                        || divisionName.equals(province)) {
                    pcEntity.setIsPioneer("Y");
                } else {
                    pcEntity.setIsPioneer("N");
                }
            }
            String attachmentName = obj.getAttachmentName();
            if (StringUtils.isNotEmpty(attachmentName) && !attachmentName.equals(pcEntity.getAttachmetName())) {
                pcEntity.setAttachmetName(attachmentName);
                pcEntity.setAttachmetPath(anEnum.getTaskAttachmetPath() + attachmentName);
            }
            pcEntity.setIsValid(isValid);
            if (StringUtils.isNotEmpty(updateUser)) {
                pcEntity.setUploadUser(updateUser);
            } else {
                pcEntity.setUploadUser(userId);
            }
            pcEntity.setUploadTime(updateTime);
            pcEntity.setTaskUpdateTime(updateTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pcEntity;
    }

    public DivisionVo getDivisionVo(Object obj, String[] fields) {
        DivisionVo vo = new DivisionVo();
        try {
            String province = (String) ServerUtil.getGetMethod(obj, fields[0]);
            String city = (String) ServerUtil.getGetMethod(obj, fields[1]);
            String area = (String) ServerUtil.getGetMethod(obj, fields[2]);
            vo.setProvinceName(province);
            vo.setCityName(city);
            vo.setAreaName(area);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vo;
    }

    public boolean getsubEntities(Object obj, String[] fields, String taskName) {
        DivisionVo vo = getDivisionVo(obj, fields);
        vo.setTaskName(taskName);
        if (voList.contains(vo)) {
            return false;
        } else {
            voList.add(vo);
        }
        return true;
    }

    public void clear() {
        voList.clear();
    }

    @Override
    public void exportStatistics(QueryVo queryVo, String userId, HttpServletResponse resp) {
        try {
            String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            String name = dateStr + "进度报告.xlsx";
            //resp.setContentType("application/octet-stream ");
            resp.setHeader("content-Type", "application/vnd.ms-excel");
            resp.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
            //resp.setHeader("Accept-Ranges", "bytes");// 告诉客户端允许断点续传多线程连接下载
            resp.setHeader("Content-Disposition", "attachment;fileName="
                    + new String(name.getBytes("GB2312"), "ISO8859-1"));
            resp.setCharacterEncoding("UTF-8");

            HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个Excel文件
            // 样式设置
            HSSFCellStyle columnHeadStyle = workbook.createCellStyle();
            columnHeadStyle.setFillPattern(FillPatternType.NO_FILL); // 背景
            columnHeadStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // 背景色AQUA.getIndex()
            columnHeadStyle.setBorderBottom(BorderStyle.THIN); // 下边框
            columnHeadStyle.setBorderLeft(BorderStyle.THIN);// 左边框
            columnHeadStyle.setBorderTop(BorderStyle.THIN);// 上边框
            columnHeadStyle.setBorderRight(BorderStyle.THIN);// 右边框
            columnHeadStyle.setAlignment(HorizontalAlignment.CENTER);//左右居中
            columnHeadStyle.setVerticalAlignment(VerticalAlignment.BOTTOM);// 上下居中
            columnHeadStyle.setWrapText(true);//自动换行

            HSSFSheet sheet = workbook.createSheet("进度报告");
            sheet.setColumnWidth(0, 10000);
            String[] sheetHeadTitle = new String[]{"序号", "省", "市", "区(县)", "是否是试点县", "任务详情(文件名)", "上传时间", "上传者"};
            //ConvertUtils.register(new DateConverter(null), java.util.Date.class);
            StatisticsEnum anEnum = StatisticsEnum.getInstanceByName(queryVo.getTaskName());
            queryVo.setTaskName(anEnum.getTaskName());
            List<PcStatisticsFillEntity> pcEntities = pcStatisticsFillNativeRepository.findNoPage(queryVo, userId);
            List<UsersVo> usersVoList = usersInfoRepository.getAll();
            for (PcStatisticsFillEntity pcEntity : pcEntities) {
                String isPioneer = pcEntity.getIsPioneer();
                String uploadUser = pcEntity.getUploadUser();
                for (UsersVo usersVo : usersVoList) {
                    if ("Y".equals(isPioneer)) {
                        pcEntity.setIsPioneer("是");
                    } else {
                        pcEntity.setIsPioneer("否");
                    }
                    if (usersVo.getUsersId().equals(uploadUser)) {
                        pcEntity.setUploadUser(usersVo.getUsersName());
                        break;
                    }
                }
            }
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, sheetHeadTitle.length - 1));
            for (int i = 0; i < pcEntities.size() + 2; i++) {
                HSSFRow row0 = sheet.createRow(i);
                row0.setHeightInPoints(30);
                for (int t = 0; t < sheetHeadTitle.length; t++) {
                    HSSFCell cel0_i = row0.createCell(t);
                    if (i == 0 && t == 0) {
                        cel0_i.setCellValue(new HSSFRichTextString("普查进度填报表-" + anEnum.getTaskName()));
                    } else if (i == 1) {
                        cel0_i.setCellValue(new HSSFRichTextString(sheetHeadTitle[t]));
                    } else if (i > 1) {
                        if (t == 0) {
                            cel0_i.setCellValue(new HSSFRichTextString(String.valueOf(i - 1)));
                        } else {
                            String[] values = CheckObjFields.objectChangeArray(pcEntities.get(i - 2));
                            cel0_i.setCellValue(new HSSFRichTextString(values[t + 3]));
                        }
                    }
                    cel0_i.setCellStyle(columnHeadStyle);
                    sheet.autoSizeColumn((short) t);//宽度自适应
                }

            }
            OutputStream out = resp.getOutputStream();
            workbook.write(out);
            // ByteArrayOutputStream bos = new ByteArrayOutputStream();
            // workbook.write(bos);
            // bos.writeTo(out);
            if (out != null) {
                out.flush();
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
